﻿Public Class frmThamSo

    Private Sub frmThamSo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LayDSThamSo()
    End Sub

    Private Sub LayDSThamSo()
        Try
            Dim tsBUS As New ThamSoBUS
            Dim ds As New List(Of ThamSoDTO)

            ds = tsBUS.LayDanhSachThamSo()

            For Each ts As ThamSoDTO In ds
                txtSoTietToiDa.Text = ts.SoTietToiDa.Trim()
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub btCapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCapNhat.Click
        Try
            If (txtSoTietToiDa.Text.Trim.Length = 0) Then
                MessageBox.Show("Nhap So Tiet Toi Da.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return
            End If

            Dim tsDTO As New ThamSoDTO()
            Dim tsBUS As New ThamSoBUS()
            Dim kq As Integer = -1

            tsDTO.SoTietToiDa = txtSoTietToiDa.Text.Trim()

            kq = tsBUS.CapNhatThamSo(tsDTO)

            If kq > 0 Then
                LayDSThamSo()
            Else
                MessageBox.Show("Cap Nhat that bai.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub btThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btThoat.Click
        Me.Close()
    End Sub
End Class